import api from '../../utils/http'

/* function addUser(data) {
  return function (dispatch) {
    dispatch({
      type: 'addUser',
      data: {}
    })
  }
} */


// 静态json对象方法  添加用户
const addUserJson = data => ({
  type: 'addUser',
  payload: data
})

// 用户列表
const getUsersJson = data => ({
  type: 'getusers',
  payload: data
})

const getUsersPageJson = data => ({
  type: 'getuserspage',
  payload: data
})



// data用于ajax所用
export const addUser = data => dispatch => {
  // 网络请求
  api.addUser(data).then(ret => dispatch(addUserJson(ret.data.data)))
}

// data用于ajax所用
export const getUsers = () => dispatch => {
  api.getUser().then(ret => dispatch(getUsersJson(ret.data.data)))
}

// data用于ajax所用 分页
export const getUsersPage = (page) => dispatch => {
  api.getUser(page).then(ret => dispatch(getUsersPageJson(ret.data.data)))
}

// 清空一下数据中的users
export const clearStateUsers = () => ({
  type: 'clearusers',
  payload: []
})